package com.alibaba.travel.article.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import com.alibaba.travel.article.entity.SpecialColumnEntity;
import com.alibaba.travel.article.service.SpecialColumnService;
import com.alibaba.travel.common.utils.PageUtils;
import com.alibaba.travel.common.utils.R;



/**
 * 专栏表
 *
 * @author wherezy
 * @email wherezy@tom.com
 * @date 2023-02-27 09:17:25
 */
@Api(tags = {"专栏表SpecialColumnController"})
@RestController
@RequestMapping("article/specialcolumn")
public class SpecialColumnController {
    @Autowired
    private SpecialColumnService specialColumnService;

    /**
     * 专栏删除文章
     */
    @ApiOperation(value="专栏删除文章", notes="专栏id 和 文章ids")
    @PostMapping("/deleteArticle")
    public R deleteArticle(@RequestParam Long columnId, Long[] articleIds){
        try {
            specialColumnService.deleteArticle(columnId, articleIds);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok();
    }

    /**
     * 专栏添加文章
     */
    @ApiOperation(value="专栏添加文章", notes="专栏id 和 文章ids")
    @PostMapping("/addArticle")
    public R addArticle(@RequestParam Long columnId, Long[] articleIds){
        try {
            specialColumnService.addArticle(columnId, articleIds);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok();
    }

    /**
     * 分页私人专栏列表
     */
    @ApiOperation(value="分页私人文章列表", notes="k-v map形式封装分页参数 + 排序")
    @PostMapping("/privateList")
    public R privateArticle(@RequestBody Map<String, Object> params){
        PageUtils page = null;
        try {
            page = specialColumnService.queryPrivateArticlePage(params);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @ApiOperation(value="分页获取信息", notes="k-v map形式封装分页参数")
    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = specialColumnService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value="获取信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpecialColumnEntity specialColumn = specialColumnService.getById(id);

        return R.ok().put("specialColumn", specialColumn);
    }

    /**
     * 保存
     */
    @ApiOperation(value="保存")
    @PostMapping("/save")
    public R save(@RequestBody SpecialColumnEntity specialColumn){
		specialColumnService.save(specialColumn);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改")
    @PostMapping("/update")
    public R update(@RequestBody SpecialColumnEntity specialColumn){
		specialColumnService.updateById(specialColumn);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value="删除")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		specialColumnService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
